#define  _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    int wiggleMaxLength(vector<int>& nums) {
        int size = nums.size();
        if (size == 1) return 1;

        int prev_dif = nums[1] - nums[0];
        int prev_num = nums[1];
        int count = prev_dif == 0 ? 1 : 2;

        for (int i = 2; i < size; i++)
        {
            int e = nums[i];
            int cur_dif = e - prev_num;
            if (cur_dif == 0)
                continue;
            if (prev_dif * cur_dif <= 0)
                count++;
            prev_num = e;
            prev_dif = cur_dif;
        }

        return count;
    }
};